<template>
    <el-dialog class="dialog" :destroy-on-close="true" title="添加梯控授权" :visible.sync="isShow" :close-on-click-modal="false"
        @close="onDialogClose">
        <el-form ref="form" label-width="auto" class="form" :model="formData" :rules="rules">
            <el-form-item label="梯控" prop="door_sn">
                <el-select
                    v-model="formData.door_sn"
                    placeholder="请选择授权梯控"
                >
                    <el-option
                        v-for="item in ladderData"
                        :key="item.door_sn"
                        :label="item.door_name"
                        :value="item.door_sn"
                    ></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="onDialogClose">取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </div>
    </el-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Action } from 'vuex-class';
import { mixinDialogForm } from "@/mixin/dialog/Form";
@Component({
    mixins: [mixinDialogForm]
})
export default class ladderScripPortLadderAdd extends Vue {
    @Action("equipmentLadderscrip/portLadderAdd") itemAdd: any;

    selectItem!: any;
    addInit() {
        const me = this as any;
        me.formData.scrip_sn = me.selectItem.scrip_sn;
        me.getLadderMethod(me.selectItem.scrip_sn);
    }
    // 获取下拉选择的梯控
    ladderData:any = [];
    @Action('equipmentLadderscrip/scripLadderAddedList') getLadder: any;
    getLadderMethod() {
        const me = this as any;
        me.getLadder({ scrip_sn: me.selectItem.scrip_sn }).then(({ data }) => {
            me.ladderData = data;
        });
    }

    // 表单数据
    formData: any = {
        door_sn: "",
        scrip_sn: ""
    };

    /**
     * 校验配置
     *
     * @type {*}
     * @memberof mixinViewRules
     */
    rules: any = {
        door_sn: [
            {
                required: true,
                message: "请选择梯控",
                trigger: "blur"
            }
        ],
        scrip_sn: [
            {
                required: true
            }
        ]
    };
}
</script>
